package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    UserMapper userMapper;

    @RequestMapping("/deluser")
    public String delUser(){
        int res=userMapper.deluser("Naruto");
        if(res>0){
            return "删除成功";
        }else{
            return "删除失败";
        }
    }

    @RequestMapping("/adduser")
    public String addUser(){
        User user=new User();
        user.setStunum("050531");
        user.setPwd("hahaha");
        user.setSex("male");
        user.setStuname("zm");
        int res=userMapper.adduser(user);
        if(res>0){
            return "添加成功";
        }else{
            return "添加失败";
        }
    }

    @RequestMapping("/upduser")
    public String updUser(){
        User user=new User();
        user.setStuname("zyf");
        user.setPwd("hehehe");
        user.setStunum("050518");
        user.setSex("male");
        int res= userMapper.upduser(user);
        if(res>0){
            return "更改成功";
        }else{
            return "更改失败";
        }
    }

    @RequestMapping("/getaddr")
    public String getAddr(){
        return userMapper.getaddr("Luffy");
    }

    @RequestMapping("/getuser")
    public User getUser(){
        return userMapper.getuser("zyf");
    }

    @RequestMapping("/getall")
    public List<User> getAll(){
        return userMapper.getall();
    }

    @RequestMapping("/getlike")
    public List<User> getLike(){
        return userMapper.getlike("0505");
    }
}
